﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Collections;
using Microsoft.ApplicationBlocks.Data;

namespace KP_CommonLibrary.KP_DataAccess
{
    public class KP_DataAccess
    {
        public static DataTable Get_DataTable(string sqlSelect)
        {
            DataTable dtTemp = new DataTable();
            try
            {
                SqlConnection Cnn = new SqlConnection(KP_ObjectReferences.KP_OCnnSql.Cnn_String);
                Cnn.Open();

                SqlCommand Cmd = Cnn.CreateCommand();
                Cmd.CommandText = sqlSelect;
                Cmd.CommandType = CommandType.Text;

                SqlDataAdapter Da = new SqlDataAdapter(Cmd);
                Da.Fill(dtTemp);
             
                if (Cnn.State == ConnectionState.Open)
                Cnn.Close();
            
                return dtTemp;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void Exec_Command(string sqlcommand)
        {
            try
            {
                SqlConnection Cnn = new SqlConnection(KP_ObjectReferences.KP_OCnnSql.Cnn_String);
                Cnn.Open();

                SqlCommand Cmd = Cnn.CreateCommand();
                Cmd.CommandText = sqlcommand;
                Cmd.CommandType = CommandType.Text;

                Cmd.ExecuteNonQuery();

                if (Cnn.State == ConnectionState.Open)
                    Cnn.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static void Exec_Command(string store_name, SqlParameter[] sql_parameters)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(KP_ObjectReferences.KP_OCnnSql.Cnn_String, store_name, sql_parameters);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
